﻿using System;
using System.Data;
using System.Windows.Forms;
using BLL;

namespace GUI
{
    public partial class frmKy : DevComponents.DotNetBar.Office2007Form
    {
        private BOKy _ky;
        private DataSet _ds;
        private BOLop _lop;
        private BOMonHoc _monhoc;
        private DataSet _dsMonHoc;
        public frmKy()
        {
            InitializeComponent();
        }

        private void frmKy_Load(object sender, EventArgs e)
        {
            //Load dữ liệu ra combobox Kỳ
            _ky = new BOKy();
            _ds = _ky.Binding();
            cbxKy.DataSource = _ds.Tables[0];
            cbxKy.DisplayMember = "TenKy";
            cbxKy.ValueMember = "Ky";

            //Load danh sách lớp có trong hệ thống
            _lop = new BOLop();
            _ds = _lop.Binding();
            clbLop.DataSource = _ds.Tables[0];
            clbLop.DisplayMember = "TenLop";
            clbLop.ValueMember = "TenLop";
        }


        private void cbxKy_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedKy = (cbxKy.SelectedIndex)+1;
            _ds = _ky.GetLopByKy(selectedKy);
            for (int i = 0; i < clbLop.Items.Count; i++)
            {
                clbLop.SetItemCheckState(i, CheckState.Unchecked);
            }
            for (int i = 0; i < clbLop.Items.Count; i++)
            {
                var dataRowView = (DataRowView)clbLop.Items[i];
                if (dataRowView["Ky"].ToString().Equals(selectedKy.ToString()))
                {
                    clbLop.SetItemCheckState(i, CheckState.Checked);
                }
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Dispose();
        }
    }
}